<?php
declare (strict_types=1);

namespace app\common\model\discovery;

use app\common\logic\Attach;
use app\common\model\BaseModel;

/**
 * 定义发现页模型
 * @method join(string $string, string $string1)
 */
class DiscoveryData extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'site_discovery_data';

    /**
     * 定义表主键
     *
     * @var string
     */
    protected $pk = 'id';

    // 定义全局的查询范围
    protected $globalScope = ['status', 'mhm'];

    public function scopeStatus($query)
    {
        // $query->where('status', 1);
    }

    public function scopeMhm($query)
    {
        $query->where('mhm_id', request()->mhm_id);
    }

    public function iconUrl()
    {
        return $this->belongsTo(Attach::class, 'icon', 'id')->bind(['icon_url' => 'fileurl']);
    }

    public function conf()
    {
        return $this->belongsTo(Discovery::class, 'config_id', 'id');
    }
}
